<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>设置我的资料</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__PUBLIC__/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__PUBLIC__/layuiadmin/style/admin.css" media="all">
</head>

<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">设置我的资料</div>
          <div class="layui-card-body" pad15>

            <div class="layui-form" lay-filter="">
              <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="password" value="" autocomplete="off" placeholder="请输入原密码" lay-verify="required"
                    class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                  <input id="LAY_password_new" type="password" name="passwordNew" value="" autocomplete="off" placeholder="请输入新密码"
                    class="layui-input" lay-verify="passwordNew">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="repasswordNew" value="" autocomplete="off" placeholder="请输入确认密码"
                    class="layui-input" lay-verify="repasswordNew">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-block">
                  <input type="hidden" name="id" value="{$user['id']}">
                  <button class="layui-btn" lay-submit lay-filter="setmyinfo">确认修改</button>
                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
    </div>
  </div>

  <script src="__PUBLIC__/layuiadmin/layui/layui.js"></script>
  <script>
    layui.config({
      base: '__PUBLIC__/layuiadmin/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
      var $ = layui.$
        , layer = layui.layer
        , form = layui.form

      //自定义验证
      form.verify({
        //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
        passwordNew: [
          /^[\S]{6,12}$/
          , '密码必须6到12位，且不能出现空格'
        ]

        //确认密码
        , repasswordNew: function (value) {
          if (value !== $('#LAY_password_new').val()) {
            return '两次密码输入不一致';
          }
        }
      });

      //设置我的资料
      form.on('submit(setmyinfo)', function (obj) {
          // layer.msg(JSON.stringify(obj.field));

          //提交修改
          $.ajax({
            url: "{:U('Admin/Profile/passwordEdit')}",
            type: 'post',
            data: obj.field,
            success: function (re) {
              if (re.code == 0) {
                //登入成功的提示与跳转
                layer.msg(re.msg, {
                  offset: '15px'
                  , icon: 6
                  , time: 1000
                }, function () {
                  window.parent.location.reload(); //数据刷新
                });
              } else {
                layer.msg(re.msg, { icon: 5 });
              }
            }
          });
          return false;
        });
      });

  </script>
</body>

</html>